const { ListNode } = require('./base')

const partition = function (head, x) {
  const dummy1 = new ListNode(-1)
  const dummy2 = new ListNode(-1)
  let p1 = dummy1
  let p2 = dummy2
  let p = head
  while (p) {
    let newNode = new ListNode(p.val)
    if (p.val < x) {
      p1.next = newNode
      p1 = p1.next
    } else {
      p2.next = newNode
      p2 = p2.next
    }
    p = p.next
  }
  p1.next = dummy2.next
  return dummy1.next
}
